package com.mibviewer.ui.controller;

import java.awt.Component;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import com.mibviewer.common.Disposable;

public class ActionMap implements Disposable
{
	private Map<String,List<Component>> controls;
	
	public ActionMap()
	{
		controls = new HashMap<String,List<Component>>();
	}
	
	public void addComponent(String actionCommand,Component component)
	{
		List<Component> components = controls.get(actionCommand);
		if(component==null)
		{
			components = new LinkedList<Component>();
			controls.put(actionCommand,components);
		}
		components.add(component);
	}

	public void enable(String actionCommand)
	{
		setStatus(actionCommand,true);
	}

	public void disable(String actionCommand)
	{
		setStatus(actionCommand,false);
	}
	
	
	private void setStatus(String actionCommand,boolean enabled)
	{
		List<Component> components = controls.get(actionCommand);
		if(components!=null)
		{
			for(Component component : components)
			{
				component.setEnabled(enabled);
			}
		}
	}
	
	public void dispose() 
	{
		for(Entry<String,List<Component>> entry : controls.entrySet())
		{
			entry.getValue().clear();
		}
		controls.clear();
	}
	
	
}
